package router

import (
	"enjoy_wangyashuo/internal/api"
	"enjoy_wangyashuo/internal/api/user"
	"enjoy_wangyashuo/pkg"
	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
	"time"
)

func Router(r *gin.Engine) {
	// 简单的路由组: v
	r.Use(cors.New(cors.Config{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"*"},
		AllowHeaders:     []string{"*"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
		AllowOriginFunc: func(origin string) bool {
			return origin == "https://github.com"
		},
		MaxAge: 12 * time.Hour,
	}))
	v1 := r.Group("/user")
	{
		v1.POST("/login", user.Login)
		v1.POST("/register", user.Register)
		v1.POST("/sendCode", user.SendCode)
	}
	add := r.Group("/add", pkg.JWTAuth("2206A"))
	{
		add.POST("/create/addr", user.CreateAddr)
		add.POST("/update/password/userid", user.UpdatePasswordByUserId)
		add.POST("/get/addr/list/userid", user.GetAddrListByUserId)
	}
	good := r.Group("/good")
	{
		good.POST("/goods/detail", api.GoodsDetail)
		good.POST("/get/sku/info", api.GetSkuInfo)
		good.POST("/search/goods/list", api.SearchGoodsList)
		good.POST("/category/list", api.CategoryList) //查询分类列表
		good.POST("/category/location/list", api.CategoryLocationList)
		good.POST("/category/by/id/goods/info", api.CategoryBYIDGoodsInfo)
	}
}
